class NestedInteger(object):
   def isInteger(self):
       """
       @return True if this NestedInteger holds a single integer, rather than a nested list.
       :rtype bool
       """

   def getInteger(self):
       """
       @return the single integer that this NestedInteger holds, if it holds a single integer
       Return None if this NestedInteger holds a nested list
       :rtype int
       """

   def getList(self):
       """
       @return the nested list that this NestedInteger holds, if it holds a nested list
       Return None if this NestedInteger holds a single integer
       :rtype List[NestedInteger]
       """

class NestedIterator(object):

    def __init__(self, nestedList):
        """
        Initialize your data structure here.
        :type nestedList: List[NestedInteger]
        """
        self.stack = self.build(nestedList)
        self.index = 0
        self.n = len(self.stack)

    def build(self, nestedList):
        out = []
        for i in range(len(nestedList)):
            if nestedList[i].isInteger():
                out.append(nestedList[i].getInteger())
            else:
                out += self.build(nestedList[i].getList())
        return out


    def next(self):
        """
        :rtype: int
        """
        val = self.stack[self.index]
        self.index += 1
        return val

    def hasNext(self):
        """
        :rtype: bool
        """
        return self.index < self.n
